import datetime
from applications.extensions import db


class Message(db.Model):
    __tablename__ = "pest_message"
    # id自增
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='ID')
    content = db.Column(db.Text, nullable=False, comment='问题内容')
    reply = db.Column(db.Text, nullable=True, comment='回复内容')

    userid = db.Column(db.Text, nullable=False, comment='提问人id')
    repid = db.Column(db.Text, nullable=True, comment='回复人id')

    create_at = db.Column(db.DateTime, default=datetime.datetime.now, comment='提问时间')
    update_at = db.Column(db.DateTime, onupdate=datetime.datetime.now, comment='回复时间')

    isreply = db.Column(db.Integer, nullable=False, default=0, comment='是否已回复')

    def __init__(self, content, reply, userid, repid, create_at, isreply):
        self.content = content
        self.reply = reply
        self.userid = userid
        self.repid = repid
        self.create_at = create_at
        self.isreply = isreply

    def update(self, entry):
        self.content = entry.content
        self.reply = entry.reply
        self.userid = entry.userid
        self.repid = entry.repid
        self.create_at = entry.create_at
        self.update_at = entry.update_at
        self.isreply = entry.isreply
